﻿using System;
using System.Windows.Forms;
using System.IO;
using System.Text;
using System.Collections.Generic;

namespace 简易漫画阅读器
{
    public partial class Form1 : Form
    {
        string Html, WorkPath, SavePath;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == folderBrowserDialog1.ShowDialog())
            {
                if (!backgroundWorker1.IsBusy)
                {
                    WorkPath = textBox1.Text = folderBrowserDialog1.SelectedPath;
                    backgroundWorker1.RunWorkerAsync();
                }
            }
        }

        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            var list = new List<string>();
            list.AddRange(Directory.GetFiles(WorkPath, "*.bmp"));
            list.AddRange(Directory.GetFiles(WorkPath, "*.png"));
            list.AddRange(Directory.GetFiles(WorkPath, "*.jpg"));
            if (list.Count > 0)
            {
                Html = Ulti.AddElement(list);
                SavePath = Path.GetTempFileName();
                File.AppendAllText(SavePath, Html, Encoding.UTF8);
            }
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            webBrowser1.Navigate(SavePath);
        }
    }
}
